//
//  WKTextViewController.m
//  ourToken
//
//  Created by wakeup on 2018/6/20.
//  Copyright © 2018年 ourtoken. All rights reserved.
//

#import "WKTextViewController.h"
#import "WKBaseHeader.h"

@interface WKTextViewController ()

@property (weak, nonatomic) IBOutlet UILabel *mnemonicEditText;//助记词
@property (weak, nonatomic) IBOutlet UIButton *refreshMnemonicBtn;//刷新助记词按钮
@property (weak, nonatomic) IBOutlet UILabel *privateEditText;//私钥
@property (weak, nonatomic) IBOutlet UILabel *addressEditText;//地址
@property (weak, nonatomic) IBOutlet UIButton *genPrivateBtn;//获取私钥和地址按钮
@property (weak, nonatomic) IBOutlet UILabel *address2EditText;//地址
@property (weak, nonatomic) IBOutlet UIButton *privateToAddressBtn;//私钥转地址按钮
@property (weak, nonatomic) IBOutlet UIButton *buildBtcBtn;//生成BTC交易
@property (weak, nonatomic) IBOutlet UIButton *buildEthBtn;//生成ETH交易

@end

@implementation WKTextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationView];
    
    [self.refreshMnemonicBtn addTarget:self action:@selector(refreshMnemonicBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.genPrivateBtn addTarget:self action:@selector(genPrivateBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.privateToAddressBtn addTarget:self action:@selector(privateToAddressBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.buildBtcBtn addTarget:self action:@selector(clickBuildBtcBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.buildEthBtn addTarget:self action:@selector(clickBuildEthBtn:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setNavigationView {
    [super setNavigationView];
    self.navigationView.topTitleLabel.text = @"连接设备";
    self.navigationView.backgroundColor = [UIColor clearColor];
}

//刷新助记词
- (void)refreshMnemonicBtnClick:(id)refreshMnemonicBtnClick {
    self.mnemonicEditText.text = [WKBlockChainManager refreshMnemonic];
}

//获取私钥和地址
- (void)genPrivateBtnClick:(id)genPrivateBtnClick {
    NSArray* addressPrivateKeyArray = [WKBlockChainManager getPrivateAndAddressFormMnemonic:self.mnemonicEditText.text type:3];
    self.addressEditText.text = addressPrivateKeyArray[0];
    self.privateEditText.text = addressPrivateKeyArray[1];
}

//私钥转地址
- (void)privateToAddressBtnClick:(id)genPrivateBtnClick {
    self.address2EditText.text = [WKBlockChainManager addressFormPrivate:self.privateEditText.text];
}

//生成比特币交易
- (void)clickBuildBtcBtn:(id)btn {
    NSString *data = [WKBlockChainManager buildBtcTransactionWithPrivate:nil dict:nil];
    
    UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"BTC交易数据" message:data delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertview show];
}

//生成以太坊交易
- (void)clickBuildEthBtn:(id)btn {
    NSString *data = [WKBlockChainManager buildEthTransactionWithPrivate:nil dict:nil];
    UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"ETH交易数据" message:data delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertview show];
}

@end
